replace C40STATERAW = proper(C40STATERAW)
gen     C40STATE    =   .

********************************************************************************
****         b. United States                                               ****
********************************************************************************
replace C40STATE =  41 if strpos(C40STATERAW,"Alabama"                       ) > 0 & C40STATE == .
replace C40STATE =  81 if strpos(C40STATERAW,"Alaska"                        ) > 0 & C40STATE == .
replace C40STATE =  61 if strpos(C40STATERAW,"Arizona"                       ) > 0 & C40STATE == .
replace C40STATE =  42 if strpos(C40STATERAW,"Arkansas"                      ) > 0 & C40STATE == .
replace C40STATE =  71 if strpos(C40STATERAW,"California"                    ) > 0 & C40STATE == .
replace C40STATE =  62 if strpos(C40STATERAW,"Colorado"                      ) > 0 & C40STATE == .
replace C40STATE =   1 if strpos(C40STATERAW,"Connecticut"                   ) > 0 & C40STATE == .
replace C40STATE =  11 if strpos(C40STATERAW,"Delaware"                      ) > 0 & C40STATE == .
replace C40STATE =  98 if strpos(C40STATERAW,"District of Columbia"          ) > 0 & C40STATE == .
replace C40STATE =  43 if strpos(C40STATERAW,"Florida"                       ) > 0 & C40STATE == .
replace C40STATE =  44 if strpos(C40STATERAW,"Georgia"                       ) > 0 & C40STATE == .
replace C40STATE =  82 if strpos(C40STATERAW,"Hawaii"                        ) > 0 & C40STATE == .
replace C40STATE =  63 if strpos(C40STATERAW,"Idaho"                         ) > 0 & C40STATE == .
replace C40STATE =  21 if strpos(C40STATERAW,"Illinois"                      ) > 0 & C40STATE == .
replace C40STATE =  22 if strpos(C40STATERAW,"Indiana"                       ) > 0 & C40STATE == .
replace C40STATE =  31 if strpos(C40STATERAW,"Iowa"                          ) > 0 & C40STATE == .
replace C40STATE =  32 if strpos(C40STATERAW,"Kansas"                        ) > 0 & C40STATE == .
replace C40STATE =  51 if strpos(C40STATERAW,"Kentucky"                      ) > 0 & C40STATE == .
replace C40STATE =  45 if strpos(C40STATERAW,"Louisiana"                     ) > 0 & C40STATE == .
replace C40STATE =   2 if strpos(C40STATERAW,"Maine"                         ) > 0 & C40STATE == .
replace C40STATE =  52 if strpos(C40STATERAW,"Maryland"                      ) > 0 & C40STATE == .
replace C40STATE =   3 if strpos(C40STATERAW,"Massachusetts"                 ) > 0 & C40STATE == .
replace C40STATE =  23 if strpos(C40STATERAW,"Michigan"                      ) > 0 & C40STATE == .
replace C40STATE =  33 if strpos(C40STATERAW,"Minnesota"                     ) > 0 & C40STATE == .
replace C40STATE =  46 if strpos(C40STATERAW,"Mississippi"                   ) > 0 & C40STATE == .
replace C40STATE =  34 if strpos(C40STATERAW,"Missouri"                      ) > 0 & C40STATE == .
replace C40STATE =  64 if strpos(C40STATERAW,"Montana"                       ) > 0 & C40STATE == .
replace C40STATE =  35 if strpos(C40STATERAW,"Nebraska"                      ) > 0 & C40STATE == .
replace C40STATE =  65 if strpos(C40STATERAW,"Nevada"                        ) > 0 & C40STATE == .
replace C40STATE =   4 if strpos(C40STATERAW,"New Hampshire"                 ) > 0 & C40STATE == .
replace C40STATE =  12 if strpos(C40STATERAW,"New Jersey"                    ) > 0 & C40STATE == .
replace C40STATE =  66 if strpos(C40STATERAW,"New Mexico"                    ) > 0 & C40STATE == .
replace C40STATE =  13 if strpos(C40STATERAW,"New York"                      ) > 0 & C40STATE == .
replace C40STATE =  47 if strpos(C40STATERAW,"North Carolina"                ) > 0 & C40STATE == .
replace C40STATE =  36 if strpos(C40STATERAW,"North Dakota"                  ) > 0 & C40STATE == .
replace C40STATE =  24 if strpos(C40STATERAW,"Ohio"                          ) > 0 & C40STATE == .
replace C40STATE =  53 if strpos(C40STATERAW,"Oklahoma"                      ) > 0 & C40STATE == .
replace C40STATE =  72 if strpos(C40STATERAW,"Oregon"                        ) > 0 & C40STATE == .
replace C40STATE =  14 if strpos(C40STATERAW,"Pennsylvania"                  ) > 0 & C40STATE == .
replace C40STATE =   5 if strpos(C40STATERAW,"Rhode Island"                  ) > 0 & C40STATE == .
replace C40STATE =  48 if strpos(C40STATERAW,"South Carolina"                ) > 0 & C40STATE == .
replace C40STATE =  37 if strpos(C40STATERAW,"South Dakota"                  ) > 0 & C40STATE == .
replace C40STATE =  54 if strpos(C40STATERAW,"Tennessee"                     ) > 0 & C40STATE == .
replace C40STATE =  49 if strpos(C40STATERAW,"Texas"                         ) > 0 & C40STATE == .
replace C40STATE =  67 if strpos(C40STATERAW,"Utah"                          ) > 0 & C40STATE == .
replace C40STATE =   6 if strpos(C40STATERAW,"Vermont"                       ) > 0 & C40STATE == .
replace C40STATE =  40 if strpos(C40STATERAW,"Virginia"                      ) > 0 & C40STATE == .
replace C40STATE =  73 if strpos(C40STATERAW,"Washington"                    ) > 0 & C40STATE == .
replace C40STATE =  56 if strpos(C40STATERAW,"West Virginia"                 ) > 0 & C40STATE == .
replace C40STATE =  25 if strpos(C40STATERAW,"Wisconsin"                     ) > 0 & C40STATE == .
replace C40STATE =  68 if strpos(C40STATERAW,"Wyoming"                       ) > 0 & C40STATE == .

********************************************************************************
****         c. Foreign countries                                           ****
********************************************************************************
replace C40STATE = 150 if strpos(C40STATERAW,"Canada"                        ) > 0 & C40STATE == .
replace C40STATE = 434 if strpos(C40STATERAW,"Italy"                         ) > 0 & C40STATE == .
replace C40STATE = 453 if strpos(C40STATERAW,"Germany"                       ) > 0 & C40STATE == .
replace C40STATE = 410 if strpos(C40STATERAW,"England"                       ) > 0 & C40STATE == .
replace C40STATE = 200 if strpos(C40STATERAW,"Mexico"                        ) > 0 & C40STATE == .
replace C40STATE = 455 if strpos(C40STATERAW,"Poland"                        ) > 0 & C40STATE == .
replace C40STATE = 515 if strpos(C40STATERAW,"Philippines"                   ) > 0 & C40STATE == .
replace C40STATE = 414 if strpos(C40STATERAW,"Ireland"                       ) > 0 & C40STATE == .
replace C40STATE = 465 if strpos(C40STATERAW,"Russia"                        ) > 0 & C40STATE == .
replace C40STATE = 110 if strpos(C40STATERAW,"Puerto Rico"                   ) > 0 & C40STATE == .
replace C40STATE = 500 if strpos(C40STATERAW,"China"                         ) > 0 & C40STATE == .
replace C40STATE = 450 if strpos(C40STATERAW,"Austria"                       ) > 0 & C40STATE == .
replace C40STATE = 452 if strpos(C40STATERAW,"Czechoslovakia"                ) > 0 & C40STATE == .
replace C40STATE = 433 if strpos(C40STATERAW,"Greece"                        ) > 0 & C40STATE == .
replace C40STATE = 454 if strpos(C40STATERAW,"Hungary"                       ) > 0 & C40STATE == .
replace C40STATE = 405 if strpos(C40STATERAW,"Sweden"                        ) > 0 & C40STATE == .
replace C40STATE = 130 if strpos(C40STATERAW,"Panama"                        ) > 0 & C40STATE == .
replace C40STATE = 404 if strpos(C40STATERAW,"Norway"                        ) > 0 & C40STATE == .
replace C40STATE = 457 if strpos(C40STATERAW,"Yugoslavia"                    ) > 0 & C40STATE == .
replace C40STATE = 421 if strpos(C40STATERAW,"France"                        ) > 0 & C40STATE == .
replace C40STATE = 456 if strpos(C40STATERAW,"Romania"                       ) > 0 & C40STATE == .
replace C40STATE = 250 if strpos(C40STATERAW,"Cuba"                          ) > 0 & C40STATE == .
replace C40STATE = 400 if strpos(C40STATERAW,"Denmark"                       ) > 0 & C40STATE == .
replace C40STATE = 436 if strpos(C40STATERAW,"Portugal"                      ) > 0 & C40STATE == .
replace C40STATE = 425 if strpos(C40STATERAW,"Netherlands"                   ) > 0 & C40STATE == .
replace C40STATE = 542 if strpos(C40STATERAW,"Turkey"                        ) > 0 & C40STATE == .
replace C40STATE = 426 if strpos(C40STATERAW,"Swizterland"                   ) > 0 & C40STATE == .
replace C40STATE = 438 if strpos(C40STATERAW,"Spain"                         ) > 0 & C40STATE == .
replace C40STATE = 462 if strpos(C40STATERAW,"Lithuania"                     ) > 0 & C40STATE == .
replace C40STATE = 401 if strpos(C40STATERAW,"Finland"                       ) > 0 & C40STATE == .
replace C40STATE = 420 if strpos(C40STATERAW,"Belgium"                       ) > 0 & C40STATE == .
replace C40STATE = 430 if strpos(C40STATERAW,"Albania"                       ) > 0 & C40STATE == .
replace C40STATE = 451 if strpos(C40STATERAW,"Bulgaria"                      ) > 0 & C40STATE == .
replace C40STATE = 501 if strpos(C40STATERAW,"Japan"                         ) > 0 & C40STATE == .
replace C40STATE = 600 if strpos(C40STATERAW,"Egypt"                         ) > 0 & C40STATE == .

********************************************************************************
****         d. Add labels                                                  ****
********************************************************************************
lab def state_lbl 1 "Connecticut" 2 "Maine" 3 "Massachusetts" 4 "New Hampshire" 5 "Rhode Island" 6 "Vermont" 11 "Delaware" 12 "New Jersey" 13 "New York" 14 "Pennsylvania" 21 "Illinois" 22 "Indiana" 23 "Michigan" 24 "Ohio" 25 "Wisconsin" 31 "Iowa" 32 "Kansas" 33 "Minnesota" 34 "Missouri" 35 "Nebraska" 36 "North Dakota" 37 "South Dakota" 40 "Virginia" 41 "Alabama" 42 "Arkansas" 43 "Florida" 44 "Georgia" 45 "Louisiana" 46 "Mississippi" 47 "North Carolina" 48 "South Carolina" 49 "Texas" 51 "Kentucky" 52 "Maryland" 53 "Oklahoma" 54 "Tennessee" 56 "West Virginia" 61 "Arizona" 62 "Colorado" 63 "Idaho" 64 "Montana" 65 "Nevada" 66 "New Mexico" 67 "Utah" 68 "Wyoming" 71 "California" 72 "Oregon" 73 "Washington" 81 "Alaska" 82 "Hawaii" 98 "District Of Columbia" 110 "Puerto Rico" 130 "Panama" 150 "Canada" 200 "Mexico" 250 "Cuba" 400 "Denmark" 401 "Finland" 404 "Norway" 405 "Sweden" 410 "England" 414 "Ireland" 420 "Belgium" 421 "France" 425 "Netherlands" 426 "Swizterland" 430 "Albania" 433 "Greece" 434 "Italy" 436 "Portugal" 438 "Spain" 450 "Austria" 451 "Bulgaria" 452 "Czechoslovakia" 453 "Germany" 454 "Hungary" 455 "Poland" 456 "Romania" 457 "Yugoslavia" 462 "Lithuania" 465 "Russia" 500 "China" 501 "Japan" 515 "Philippines" 542 "Turkey" 600 "Egypt"
lab val C40STATE  state_lbl
